package com.ruoyi.mall.product.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.mall.product.domain.entity.PmsCategory;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author zhangqishu
 */
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Long id;

    /** 节点名称 */
    private String label;

    private Integer level;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect()
    {

    }

    public TreeSelect(PmsCategory pmsCategory)
    {
        this.id = pmsCategory.getId();
        this.label = pmsCategory.getName();
        this.level=pmsCategory.getLevel();
        if(!CollectionUtils.isEmpty(pmsCategory.getChildren())){
            this.children = pmsCategory.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }

    }


    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public List<TreeSelect> getChildren()
    {
        return children;
    }

    public void setChildren(List<TreeSelect> children)
    {
        this.children = children;
    }
}
